<script>
	// import config from './config.js'
	import * as dd from "dingtalk-jsapi"
	import {
		GetDingDingLogin
	} from '@/api/main'
	export default {

		onLaunch: function(options) {
			// return new Promise((resolve, reject) => {
			// 	setTimeout(() => {
			// 		getApp().globalData.statue = true;
			// 		resolve();
			// 	}, 2000)
			// });
			
		
			// uni.setStorageSync('empid',9827)
			const opt = this.getUrlParams('corpId')
			if (dd.env.platform !== "notInDingTalk") {
				dd.ready(() => {
					// alert("钉钉环境")
					dd.runtime.permission.requestAuthCode({
						corpId: opt.corpId,
					}).then((onSuccess) => {
						// alert("code"+JSON.stringify(onSuccess))
						uni.setStorageSync('code', onSuccess.code)
						GetDingDingLogin({
							code: onSuccess.code
						}).then(response => {
							// alert(JSON.stringify(response))
							uni.setStorageSync('empid', response.data.empId)
						})
					}, (onFail) => {})
				})
			} else {
				console.log('**************')
				alert("非钉钉环境")
				console.log('**************')
			}
		},

		// },
		// onShow: function() {
		// 	console.log('App Show')
		// },
		// onHide: function() {
		// 	console.log('App Hide')
		// }
		methods: {
			getUrlParams() {
				const params = {};
				const queryString = window.location.search || window.location.hash.split('?')[1];

				if (queryString) {
					queryString.split('&').forEach(param => {
						const [key, value] = param.split('=');
						params[key] = decodeURIComponent(value);
					});
				}

				return params;
			}
		}
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";

	body,
	html {
		background: #F8FAFE;
	}
</style>